using System;
using System.Web.UI;

using MettleSystems.dashCommerce.Core;
using OpenNetCommerce.Localization;
using SubSonic.Utilities;

namespace MettleSystems.dashCommerce.Web.install {
  public partial class install : System.Web.UI.Page {

    #region Member Variables

    private int step = 0;

    #endregion

    #region Page Events

    /// <summary>
    /// Handles the PreInit event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_PreInit(object sender, EventArgs e) {
      //set the theme for the install
      this.Page.Theme = "dashCommerce";
    }

    /// <summary>
    /// Handles the Load event of the Page control.
    /// </summary>
    /// <param name="sender">The source of the event.</param>
    /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param>
    protected void Page_Load(object sender, EventArgs e) {
      try {
        step = Utility.GetIntParameter("step");
        Control installControl = null;
        switch(step) {
          case 0:
            installControl = Page.LoadControl("~/install/controls/welcome.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallWelcome");
            break;
          case 1:
            installControl = Page.LoadControl("~/install/controls/license.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallLicense");
            break;
          case 2:
            installControl = Page.LoadControl("~/install/controls/database.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallDatabase");
            break;
          case 3:
            installControl = Page.LoadControl("~/install/controls/connectionstring.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallConnectionString");            
            break;
          case 4:
            installControl = Page.LoadControl("~/install/controls/versioncheck.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallVersionCheck");
            break;
          case 5:
            installControl = Page.LoadControl("~/install/controls/membership.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallAdministrator");            
            break;
          case 6:
            installControl = Page.LoadControl("~/install/controls/permissions.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallPermissions");
            break;
          case 7:
            installControl = Page.LoadControl("~/install/controls/complete.ascx");
            Page.Title = LocalizationUtility.GetText("titleInstallComplete");            
            break;
        }

        pnlInstall.Controls.Clear();
        pnlInstall.Controls.Add(installControl);
      }
      catch(Exception ex) {
        Logger.Error(typeof(install).Name + ".Page_Load", ex);
        Master.MessageCenter.DisplayCriticalMessage(ex.Message);
      }

    }

    #endregion


  }
}
